package com.lzm.flash;

import android.os.Bundle;

import java.util.Vector;

/**
 * Created by lzm on 2018/2/27.
 */


interface Observer
{
    public void updata(Handler handler);
}

class Handler{

    Bundle m_b=null;
    int m_tag=-1000;
    public void setData(Bundle b)
    {
        Handler.this.m_b=b;
    }

    public Bundle getData()
    {
        return m_b;
    }

    public void setTag(int tag)
    {
        m_tag=tag;
    }

    public int getTag()
    {
        return m_tag;
    }

}
interface Observerable
{
    public void registerObserver(Observer observer);
    public  void removeObsever(Observer observer);
    public  void  notifyObserver(Handler handler);
}

//不用考虑在增删观察者时的线程安全问题
class  Subject implements Observerable
{
    Vector<Observer> m_obsrvers;

    @Override
    public void registerObserver(Observer observer) {
        m_obsrvers.add(observer);
    }

    @Override
    public void removeObsever(Observer observer) {
        m_obsrvers.remove(observer);
    }

    @Override
    public void notifyObserver(Handler handler) {
        for (Observer observer:m_obsrvers) {
            observer.updata(handler);
        }
    }
}






























